<?php
namespace api\store;

use think\Cache;

class StoreRemote
{
    /**
     * @param $name
     * @param bool $default
     * @return bool|mixed
     */
    public static function data_get($name, $default = false)
    {
        $ret = StoreModel::where(['n' => $name])->cache(md5($name))->value('v');
        $content = $ret;
        if (empty($content))
            return $default;
        $content = unserialize($content);
        return $content;
    }

    /**
     * @param $name
     * @param $value
     * @return int|string
     */
    public static function data_set($name, $value)
    {
        $value = serialize($value);
        StoreModel::where(['n' => $name])->delete();
        $ret = StoreModel::where([])->insert(['n' => $name, 'v' => $value]);
        Cache::rm(md5($name));
        return $ret;
    }
}